# @Author   : XiongBinFei
# @Version  : 1.0
# @Time     : 2025/3/19 14:18

import random


def check_lottery():
    # 用户先输入号码
    user_input = input("请输入8个数字（1-33），用空格分隔：")
    user_numbers = list(map(int, user_input.split()))

    # 生成中奖号码并显示
    winning_numbers = [random.randint(1, 33) for _ in range(8)]
    print("\n※ 本期中奖号码为:", winning_numbers)

    # 检查正确数
    correct = sum(a == b for a, b in zip(winning_numbers, user_numbers))

    # 判断奖项并明确规则
    print(f"\n您的号码：{user_numbers}")
    print(f"中奖号码：{winning_numbers}")
    print(f"匹配数量：{correct}/8")
    if correct == 8:
        print("【一等奖】全号匹配！")
    elif correct == 7:
        print("【二等奖】错1个号码")
    elif correct == 6:
        print("【三等奖】错2个号码")
    elif correct == 5:
        print("【四等奖】错3个号码")
    else:
        print("未中奖")


def simulate_probability():
    # 固定目标号码
    target = [5, 12, 19, 23, 28, 30, 7, 14]  # 示例固定号码
    print("\n※ 模拟的目标号码为:", target)

    total = 10000
    counts = {1: 0, 2: 0, 3: 0, 4: 0}

    # 模拟过程
    for _ in range(total):
        generated = [random.randint(1, 33) for _ in range(8)]
        correct = sum(a == b for a, b in zip(target, generated))
        if correct == 8:
            counts[1] += 1
        elif correct == 7:
            counts[2] += 1
        elif correct == 6:
            counts[3] += 1
        elif correct == 5:
            counts[4] += 1

    # 输出结果
    print(f"\n基于目标号码 {target} 的模拟结果（{total}次）：")
    print(f"一等奖概率：{counts[1] / total:.6f}")
    print(f"二等奖概率：{counts[2] / total:.6f}")
    print(f"三等奖概率：{counts[3] / total:.6f}")
    print(f"四等奖概率：{counts[4] / total:.6f}")


if __name__ == "__main__":
    choice = input("请选择功能：1.检查中奖 2.模拟概率\n→ ")
    if choice == '1':
        check_lottery()
    elif choice == '2':
        simulate_probability()
    else:
        print("输入无效")